<script language="javascript">
  $(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    $('#fullcalendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
      },
      <? if ($vista != "") :?>
      defaultView: '<?=$vista?>',
      <? endif;?>
      editable: true,
      weekMode: 'variable',
      firstDay: 1,
      minTime: '<?=$hora_inicio?>',
      maxTime: '<?=$hora_cierre?>',
      buttonText: {
        today: '<?=__('Hoy')?>',
        month: '<?=__('Mes')?>',
        week: '<?=__('Semana')?>',
        day: '<?=__('Dia')?>'
      },
      axisFormat: 'HH:mm',
      slotMinutes: <?=$rango_horario?>,
      allDaySlot: true,
      allDayText: "Dia",
      columnFormat:{
        week: 'dddd dd',
        day: "dddd dd "
      },
      disableDragging: true,
      disableResizing: true,
      eventBackgroundColor: 'transparent',
      eventBorderColor: 'transparent',
      monthNames : ['<?=_("Enero")?>','<?=_("Febrero")?>','<?=_("Marzo")?>','<?=_("Abril")?>','<?=_("Mayo")?>','<?=_("Junio")?>','<?=_("Julio")?>','<?=_("Agosto")?>','<?=_("Septiembre")?>','<?=_("Octubre")?>','<?=_("Noviembre")?>','<?=_("Diciembre")?>'],
      monthNamesShort : ['<?=_("Enero")?>','<?=_("Febrero")?>','<?=_("Marzo")?>','<?=_("Abril")?>','<?=_("Mayo")?>','<?=_("Junio")?>','<?=_("Julio")?>','<?=_("Agosto")?>','<?=_("Septiembre")?>','<?=_("Octubre")?>','<?=_("Noviembre")?>','<?=_("Diciembre")?>'],
      dayNames: ['<?=__("Domingo")?>','<?=__("Lunes")?>','<?=__("Martes")?>','<?=__("Miercoles")?>','<?=__("Jueves")?>','<?=__("Viernes")?>','<?=__("Sabado")?>'],
      dayNamesShort: ['<?=__("Domingo")?>','<?=__("Lunes")?>','<?=__("Martes")?>','<?=__("Miercoles")?>','<?=__("Jueves")?>','<?=__("Viernes")?>','<?=__("Sabado")?>'],
    events: [
      {
          title: 'Ausente',
          allDay: true,
          start: '2012-03-01',
          end: '2012-03-12',
          className: 'bloqueado',
      },
      {
          title: 'Cerrado',
          allDay: true,
          start: '2012-02-01',
          end: '2012-02-05',
          className: 'cerrado',
      },
      {
          title: 'Disponible',
          allDay: true,
          start: '2012-02-06',
          end: '2012-02-29',
          className: 'disponible',
      },

      <? foreach ($turnos as $turno):?>
      {
        id: <?=$turno->getId()?>,
        title: '<?=$turno->getEstudio()->getCodigo()?> <?=$turno->getEstudio()->getNombre()?> \nPaciente: <?=$turno->getPaciente()?>',
        start: '<?=$turno->getFecha()?>',
        end: '<?=$turno->getFechaFin()?>',
        allDay: false,
        className: 'horario <?=($turno->getSobreturno() == 1) ? 'essobreturno' : ''?> <?=strtolower(trim($turno->getEstado()))?>',
        backgroundColor: 'ff0000',
        description: '',
      },
      <? endforeach;?>
      <? foreach ($aTotales as $dia => $c) :?>
        <? foreach ($c as $tipo => $cantidad):?>
          <? if ($cantidad != 0):?>
          {
              id: '<?=$turno->getId()?>',
              title: '<?=$cantidad?> <?=$tipo?>',
              allDay: true,
              start: '<?=$dia?>',
              className: '<?=$tipo?>',
            },
          <? endif;?>
        <? endforeach;?>
      <? endforeach;?>

      ],
      eventRender: function ( event, element, view) {
        if (view.name == "agendaDay") {
        }
      },
      eventClick: function (calEvent, jsEvent, view) {
        if (view.name != "month") {
          //cargarTurno(calEvent.id);
          cargarFormulario(0,0,calEvent.id);
        }
      },
      dayClick: function(date, allDay, jsEvent, view) {
        if (view.name == "agendaDay" || view.name == "agendaWeek") {
            fecha = $.fullCalendar.formatDate( date, "dd-MM-yyyy");
            hora = $.fullCalendar.formatDate( date, "HH:mm");
            cargarFormulario(fecha,hora,0);
        }
      },
    });
  });
</script>
<div id='fullcalendar' class="fullcalendar"></div>
